#ifndef LOGIC_H
#define LOGIC_H

#include <QJsonArray>
#include <QJsonObject>
#include <QObject>
//#include <QtZlib/QZipWriter>


typedef std::function<void(QString,int)> ProgressCallback;

class Logic :QObject
{
public:
    Logic();
    ~Logic();
    static Logic* getInstance();

    int getCurIndex();
    void setCurIndex(int idx);
    QJsonArray getItems();
    void append(QJsonObject &item);
    void updateItem(QJsonObject &item);
    void remove();
    bool isHave(QString name);
    QString getDistDir();
    QString bakDistDir();

    QJsonObject curItem();
    QJsonObject* getCurMd5info();

    void walk(ProgressCallback progress);

    std::function<void(QString)> output;
private:
    static Logic* _inst;
    QString distDir;
    void init();

    QJsonObject itemList;
    QJsonObject oldMd5Info;

    QString readFileMd5(QString filePath);

    QString refreshMd5info(ProgressCallback progress);

    // QZipWriter& zip;
    bool traverseDirectoryWithIterator(QString &rootdir,const QString &path,QStringList &filters,QJsonObject& result,ProgressCallback progress);
    bool isExistVersion;

};

#endif // LOGIC_H
